package org.dromara.demo.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.web.core.BaseService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.demo.domain.DemoExample3;
import org.dromara.demo.service.DemoExample3ServiceImpl;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 测试关联
 *
 * @author wenrui Su
 * @date 2024-04-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/demo/example3")
public class DemoExample3Controller extends BaseService {

  private final DemoExample3ServiceImpl demoExample3Service;

/**
 * 查询测试关联列表
 */
@SaCheckPermission("demo:example3:list")
@GetMapping("/list")
  public TableDataInfo<DemoExample3> list(DemoExample3 bo, PageQuery pageQuery) {
    return demoExample3Service.queryPageList(bo, pageQuery);
  }

  /**
   * 导出测试关联列表
   */
  @SaCheckPermission("demo:example3:export")
  @Log(title = "测试关联", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(DemoExample3 bo, HttpServletResponse response) {
    List<DemoExample3> list = demoExample3Service.queryList(bo);
    ExcelUtil.exportExcel(list, "测试关联", DemoExample3. class,response);
  }

  /**
   * 获取测试关联详细信息
   *
   * @param id 主键
   */
  @SaCheckPermission("demo:example3:query")
  @GetMapping("/{id}")
  public R<DemoExample3> getInfo(@NotNull(message = "主键不能为空")
                                 @PathVariable Long id) {
    return R.ok(demoExample3Service.queryById(id));
  }

  /**
   * 新增测试关联
   */
  @SaCheckPermission("demo:example3:add")
  @Log(title = "测试关联", businessType = BusinessType.INSERT)
  @RepeatSubmit()
  @PostMapping()
  public R<Void> add(@Validated(AddGroup.class) @RequestBody DemoExample3 bo) {
    return toAjax(demoExample3Service.insertByBo(bo));
  }

  /**
   * 修改测试关联
   */
  @SaCheckPermission("demo:example3:edit")
  @Log(title = "测试关联", businessType = BusinessType.UPDATE)
  @RepeatSubmit()
  @PutMapping()
  public R<Void> edit(@Validated(EditGroup.class) @RequestBody DemoExample3 bo) {
    return toAjax(demoExample3Service.updateByBo(bo));
  }

  /**
   * 删除测试关联
   *
   * @param ids 主键串
   */
  @SaCheckPermission("demo:example3:remove")
  @Log(title = "测试关联", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public R<Void> remove(@NotEmpty(message = "主键不能为空")
                        @PathVariable Long[] ids) {
    return toAjax(demoExample3Service.deleteWithValidByIds(List.of(ids), true));
  }
}
